//
//  YLDiscoveryController.m
//  YLFinanceService
//
//  Created by she1323 on 2017/8/30.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLDiscoveryController.h"
#import "YLProductViewController.h"
#import "XXPageTabView.h"
#import "XXPageTabItemLable.h"
#import "YLGlobeHeader.h"
#import "YLActivityTableViewController.h"
#import <Masonry.h>
@interface YLDiscoveryController ()<XXPageTabViewDelegate, UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIButton *memberCenter;
@property (weak, nonatomic) IBOutlet UIView *buttonBaseView;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIImageView *icon;
@property (nonatomic, strong) XXPageTabView *pageTabView;
@end

@implementation YLDiscoveryController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.scrollView.alwaysBounceVertical = YES;
    [self setUpPageTabView];
}

- (void)setUpPageTabView
{
    YLActivityTableViewController *vc1 = [[YLActivityTableViewController alloc] init];
    YLActivityTableViewController *vc2 = [[YLActivityTableViewController alloc] init];
    
    [self addChildViewController:vc1];
    [self addChildViewController:vc2];
    
    //支持网易云音乐，今日头条，微博等切换栏效果
    self.pageTabView = [[XXPageTabView alloc] initWithChildControllers:self.childViewControllers childTitles:@[@"普惠", @"银来基金"]];

    self.pageTabView.frame = CGRectMake(0,  (159 + 105) / 750.0 * YLScreenW, YLScreenW, YLScreenH - ( (159 + 105) / 750.0 * YLScreenW) - 44);
    self.pageTabView.tabSize = CGSizeMake(YLScreenW, 44.0f);
    self.pageTabView.selectedColor = YLLOrgColor;
    self.pageTabView.separatorColor = YLColor(200, 200, 200);
    self.pageTabView.unSelectedColor = YLLineColor;
    self.pageTabView.delegate = self;
    self.pageTabView.indicatorHeight = 1.5;
    self.pageTabView.titleStyle = XXPageTabTitleStyleDefault;
    self.pageTabView.indicatorStyle = XXPageTabIndicatorStyleStretch;
    self.pageTabView.indicatorWidth = YLScreenW / 2.0 - 30;
    [self.scrollView addSubview:self.pageTabView];
}

- (void)pageTabViewDidEndChange {
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    
    UITableView *firstTableView = ((UITableViewController *)self.childViewControllers[0]).tableView;
    UITableView *secondTableView = ((UITableViewController *)self.childViewControllers[0]).tableView;
    
    CGFloat placeholderOffset = 0;
    if (self.pageTabView.selectedTabIndex == 0) {
        if (firstTableView.contentOffset.y > self.pageTabView.tabView.frame.size.height - 50) {
            placeholderOffset = self.pageTabView.tabView.frame.size.height - 50;
        }
        else {
            placeholderOffset = firstTableView.contentOffset.y;
        }
        [secondTableView setContentOffset:CGPointMake(0, placeholderOffset) animated:NO];
    }
    else {
        if (secondTableView.contentOffset.y > self.pageTabView.tabView.frame.size.height - 50) {
            placeholderOffset = self.pageTabView.tabView.frame.size.height - 50;
        }
        else {
            placeholderOffset = secondTableView.contentOffset.y;
        }
        [firstTableView setContentOffset:CGPointMake(0, placeholderOffset) animated:NO];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
